home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 2.6 KB | 157 lines | [TEXT/MPS ] |
- /*
- File: CLinkedList.cp
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 2/6/95 TMH new
- 2/6/95 TMH xxx put comment here xxx
-
- To Do:
- */
-
- #ifndef __Debug__
- #include "Debug.h"
- #endif
-
- #ifndef __CLinkedList__
- #include "CLinkedList.h"
- #endif
-
-
- //-----------------------
- // C L i n k e d L i s t
- //----------------------
-
-
- //------------------------------------------------------------------------
- void CLinkedList::LinkTail(CLink* item)
- {
-
- if( fTail == 0 ) {
-
- ASSERT(fHead==0);
- fTail = item;
- fHead = item;
-
- } else {
-
- ASSERT(fHead != 0 );
- fTail->fLink = item;
- fTail = item;
-
- }
-
- fNItems++;
- item->fLink = 0;
-
- }
-
-
- //------------------------------------------------------------------------
- CLink* CLinkedList::UnlinkHead()
- {
-
- CLink* unlinkedHead = 0;
-
-
- if( fNItems != 0 ) {
-
- ASSERT((fHead!=0) && (fTail!=0));
-
- unlinkedHead = fHead;
-
- fHead = unlinkedHead->fLink;
-
- if( fHead == 0 ) {
-
- ASSERT( fTail == unlinkedHead ); // removed the last item.
- fTail = 0;
-
- }
-
-
- fNItems--;
- ASSERT(fNItems >= 0 );
-
- }
-
- return unlinkedHead;
-
-
- }
-
-
- //-----------------------------------------
- // C L i n k e d L i s t I t e r a t o r
- //------------------------------------------
-
-
- void CLinkedListIterator::UnlinkCurrentItem()
- {
- if( fCurrItem == fLinkedList->fTail ) { // last item in list
-
-
- ASSERT(fNextItem == 0 );
-
- if( fCurrItem == fLinkedList->fHead ) { // the only item in list
-
- ASSERT(fPrevItem == 0 );
-
- fLinkedList->fHead = 0;
- fLinkedList->fTail = 0; // the list now empty
- fCurrItem = 0;
-
- } else {
-
- ASSERT(fPrevItem != 0);
-
- ASSERT(fPrevItem->fLink == fCurrItem);
- fPrevItem->fLink = 0; // previous item is now the
- fLinkedList->fTail = fPrevItem; // last item in list
-
- fCurrItem = fPrevItem;
-
- }
-
- } else if( fCurrItem == fLinkedList->fHead ) { // the first item in list
-
- ASSERT(fCurrItem->fLink == fNextItem );
-
- if( fCurrItem == fLinkedList->fTail ) { // the only item in the list
-
- ASSERT(fPrevItem == 0 );
- fLinkedList->fHead = 0;
- fLinkedList->fTail = 0; // the list now empty
- fCurrItem = 0;
-
- } else {
-
- ASSERT(fPrevItem == 0 ); // the next item becomes
- fLinkedList->fHead = fCurrItem->fLink; // the first item in the list
- fNextItem = fLinkedList->fHead;
- fCurrItem = 0;
- }
-
- } else { // removing a middle item
-
- ASSERT(fPrevItem != 0 );
- ASSERT(fPrevItem->fLink == fCurrItem );
-
- fPrevItem->fLink = fCurrItem->fLink;
-
- fCurrItem = 0;
-
- }
-
- fLinkedList->fNItems--;
-
-
- }
-
-